home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-08-01 | 3.0 KB | 131 lines | [TEXT/KAHL] |
- /****
- * CNDFilePicture.c
- *
- * Copyright © 1992 NeoLogic Systems. All rights reserved.
- *
- ****/
-
- #include "NeoTypes.h"
- #include "CNDFilePicture.h"
- #include <commands.h>
- #include <CPaneBorder.h>
- #include "CNDImage.h"
- #include "CNeoDialogText.h"
-
- extern CBureaucrat *gGopher;
-
- void CNDFilePicture::INDFilePicture(
- CView *anEnclosure,
- CBureaucrat *aSupervisor,
- short aWidth,
- short aHeight,
- short aHEncl,
- short aVEncl,
- SizingOption aHSizing,
- SizingOption aVSizing)
- {
- inherited::IPicture(anEnclosure, aSupervisor, aWidth, aHeight, aHEncl,aVEncl,
- aHSizing, aVSizing);
-
- canBeGopher = TRUE;
- fImage = nil;
- }
-
- CNDFilePicture::~CNDFilePicture(void)
- {
- setImage(nil);
- }
-
- void CNDFilePicture::setImage(CNDImage *aImage)
- {
- if (fImage != aImage) {
- if (fImage)
- fImage->unrefer();
-
- if (aImage)
- aImage->referTo();
-
- fImage = aImage;
- }
- }
-
- Boolean CNDFilePicture::BecomeGopher(Boolean fBecoming)
- {
- short inset;
- if(inherited::BecomeGopher(fBecoming))
- {
- Rect r;
-
- if(fBecoming)
- itsBorder->SetPattern(&qd.black);
- else
- itsBorder->SetPattern(&qd.white);
- RefreshBorder();
- return TRUE;
- }
- else
- return FALSE;
- }
-
- void CNDFilePicture::Draw(Rect *area)
- {
- Boolean imageBusy;
- float tempHor;
- float tempVer;
- float pictHor;
- float pictVer;
- Rect tempRect;
- Rect pictRect;
- Rect frameRect;
- PicHandle pict;
-
- LongToQDRect(&aperture, &tempRect);
- InsetRect(&tempRect, 4, 4); /* leave room for border */
- frameRect = tempRect;
-
- if (fImage)
- pict = (PicHandle)fImage->getBlob();
- else
- pict = nil;
-
- if (pict) {
- imageBusy = fImage->isBlobBusy();
- fImage->setBlobBusy(TRUE); /* so the image can't be purged */
- tempHor = tempRect.right - tempRect.left;
- tempVer = tempRect.bottom - tempRect.top;
- pictRect = (**pict).picFrame;
- pictHor = pictRect.right - pictRect.left;
- pictVer = pictRect.bottom - pictRect.top;
- EraseRect(&tempRect);
- if ((tempHor > pictHor) && (tempVer > pictVer)) { /* picture is smaller than frame */
- tempRect.left += (tempHor - pictHor) / 2;
- tempRect.right = tempRect.left + pictHor;
- tempRect.top += (tempVer - pictVer) / 2;
- tempRect.bottom = tempRect.top + pictVer;
- }
- else /* at least one picture dimension is larger than frame */
- if ((pictVer / tempVer) > (pictHor / tempHor)) { /* proportionally longer in vertical dimension */
- pictHor *= tempVer / pictVer; /* scale horizontal to keep proportion */
- if (tempHor > pictHor) {
- tempRect.left += (tempHor - pictHor) / 2;
- tempRect.right = tempRect.left + pictHor;
- }
- }
- else { /* proportionally longer in horizontal dimension */
- pictVer *= tempHor / pictHor; /* scale vertical to keep proportion */
- if (tempVer > pictVer) {
- tempRect.top += (tempVer - pictVer) / 2;
- tempRect.bottom += tempRect.top + pictVer;
- }
- }
-
- fImage->draw(&tempRect);
- fImage->setBlobBusy(imageBusy); /* reset purgability of image */
- }
- else
- EraseRect(&tempRect);
-
- InsetRect(&frameRect, -1, -1); /* back out for border */
- FrameRect(&frameRect);
- }
-